package com.focusai.efairy.model.request;

import com.focusai.efairy.model.ResultInfo;
import com.focusai.efairy.model.response.LoginResponse;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 * Created by luo_guangwen on 2017/8/12.
 */

public class PasswdLoginRequest extends Request<ResultInfo<LoginResponse>> {
    private String phone;
    private String passwd;
    public PasswdLoginRequest(String phone, String passwd, Response.Listener<ResultInfo<LoginResponse>> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/login_password"), listener);
        this.phone = phone;
        this.passwd = passwd;
    }

    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_phonenumber",phone);
        addParam("efairyuser_password", passwd);
        return super.getParams();
    }

    @Override
    protected ResultInfo<LoginResponse> parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<ResultInfo<LoginResponse>>() {
        }.getType());
    }

    @Override
    protected boolean handleRawResultData() {
        return true;
    }
}

